<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('我的请款列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>是否审核：</label>
                            <select name="requestStatus" th:with="type=${@dict.getType('work_request_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>联系人：</label>
                            <input type="text" name="contacts"/>
                        </li>
                        <li>
                            <label>请款总额：</label>
                            <input type="text" name="fundAmount"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <!--                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="work:fund:add">
                                <i class="fa fa-plus"></i> 添加
                            </a>-->
            <a class="btn btn-primary" onclick="viewFund()" >
                <i class="fa fa-gavel"></i> 查看请款明细
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="work:fund:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="work:fund:remove">
                                <i class="fa fa-remove"></i> 删除
                            </a>-->
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="work:fund:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="work:fund:remove">
                <i class="fa fa-remove"></i> 打回重审
            </a>
            <a class="btn btn-primary" onclick="check()" shiro:hasPermission="work:fund:check">
                <i class="fa fa-gavel"></i> 审核
            </a>
            <a class="btn btn-primary" onclick="grant()" shiro:hasPermission="work:fund:grant">
                <i class="fa fa-money"></i> 付款
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('work:fund:edit')}]];
    var removeFlag = [[${@permission.hasPermi('work:fund:remove')}]];
    var bankNameDatas = [[${@dict.getType('work_bank')}]];
    var requestStatus = [[${@dict.getType('work_request_status')}]];
    var prefix = ctx + "work/fund";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "我的请款",
            columns: [{
                checkbox: true
            },
                {
                    field: 'requestId',
                    title: '请款ID'

                },
                {
                    field: 'contacts',
                    title: '联系人'
                },
                {
                    field: 'fundAmount',
                    title: '请款总额'
                },
                {
                    field: 'bankName',
                    title: '请款银行',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(bankNameDatas, value);
                    }
                },
                {
                    field: 'bankAccount',
                    title: '银行账号'
                },
                {
                    field: 'requestBy',
                    title: '请款人'
                },
                {
                    field: 'requestTime',
                    title: '请款时间'
                }, {
                    field: 'payTime',
                    title: '付款时间'
                },
                {
                    field: 'requestStatus',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(requestStatus, value);
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                }]
        };
        $.table.init(options);
    });
    function viewFund(){
        var requestId = $.table.selectColumns('requestId');

        if (requestId.length != 1) {
            $.modal.alertWarning("请选择一条记录查看");
            return;
        }
        var options = {
            title: '请款',
            url:ctx + "work/fund/look/"+requestId,
            btn: false
        };
        $.modal.openOptions(options);

    }
    function check() {
        var ids = $.table.selectColumns('requestId');

        if (ids.length == 0) {
            $.modal.alertWarning("请至少选择一条记录审核");
            return;
        }
        $.modal.confirm("确认要审核选中的" + ids.length + "条数据吗?", function () {

            $.post(prefix + "/check", {ids: ids.join()}, function (result) {

                if (result.code == web_status.SUCCESS) {
                    $.modal.msgSuccess("审核成功！")
                } else {
                    $.modal.msgError(result.msg);
                }
                $.table.refresh()
            });
        });
    }

    function grant() {
        var ids = $.table.selectColumns('requestId');

        if (ids.length == 0) {
            $.modal.alertWarning("请至少选择一条记录审核");
            return;
        }
        $.modal.confirm("确认要打款选中的" + ids.length + "条数据吗?", function () {

            $.post(prefix + "/grant", {ids: ids.join()}, function (result) {

                if (result.code == web_status.SUCCESS) {
                    $.modal.msgSuccess("操作成功！")
                } else {
                    $.modal.msgError(result.msg);
                }
                $.table.refresh()
            });
        });
    }
</script>
</body>
</html>